/***********************************************************
 * $Id: CommPortUtil.java 373 2013-01-22 14:25:55Z tkistel $
 * Created: 21.01.2013
 *
 * (c) 2013 Technische Hochschule Wildau
 * (University of Applied Sciences Wildau)
 * All rights reserved
 ***********************************************************/
package de.thwildau.tm.moses.netty.channel.rxtx;

import gnu.io.CommPortIdentifier;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import de.thwildau.tm.moses.internal.netty.channel.rxtx.NativeCodeInitialiser;
 

/**
 * A utility class for Comm Port handling.
 *
 * @author Thomas Kistel
 * @version $Revision: 373 $
 *
 */
public class CommPortUtil {
    
    static {
        NativeCodeInitialiser.initNativeLibDirectory();
    }

    public static List<String> getSerialCommPortIdentifiers() {
        @SuppressWarnings("rawtypes")
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        CommPortIdentifier portId;
        List<String> list = new ArrayList<>();

        while (portList.hasMoreElements()) {
            portId = (CommPortIdentifier) portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                list.add(portId.getName());
            }
        }
        return list;
    }
}
